<template>
  <a-card :bordered="false">
    <div style="display: flex; justify-content: space-between">
      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->
        <!-- <a-button type="primary" icon="download" @click="handleExportXls('用户卡券表')">导出</a-button>
      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>-->
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-menu slot="overlay">
            <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
          </a-menu>
          <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
        </a-dropdown>
      </div>
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-form-item label="状态" style="margin-right: 10px">
            <a-select
              v-model="queryParam.status"
              style="width: 120px"
              :options="[
                { label: '未领取', value: '0' },
                { label: '已领取', value: '1' },
                { label: '已到期', value: '2' },
                { label: '已使用', value: '3' },
              ]"
              allowClear
              placeholder="请选择"
              @change="searchQuery"
            />
          </a-form-item>
          <a-form-item label="用户编号" style="margin-right: 10px">
            <a-input placeholder="请输入用户编号" v-model="queryParam.userId" @pressEnter="searchQuery"></a-input>
          </a-form-item>
          <a-form-item label="用户手机号" style="margin-right: 10px">
            <a-input placeholder="请输入用户手机号" v-model="queryParam.phone" @pressEnter="searchQuery"></a-input>
          </a-form-item>
          <template>
            <a-form-item label="优惠券" style="margin-right: 10px">
              <a-input placeholder="请输入优惠券" v-model="queryParam.preferentialCertificate" @pressEnter="searchQuery"></a-input>
            </a-form-item>
            <!-- 1-不限日期  2-指定到期时间 3-领取后计算到期时间 -->
            <a-form-item label="优惠券类型" style="margin-right: 10px">
              <!-- 1-不限日期  2-指定到期时间 3-领取后计算到期时间 -->
              <a-input placeholder="请输入优惠券类型" v-model="queryParam.preferentialType" @pressEnter="searchQuery"></a-input>
            </a-form-item>
            <a-form-item label="到期时间" style="margin-right: 10px">
              <a-input placeholder="请输入到期时间" v-model="queryParam.endTime"></a-input>
            </a-form-item>
          </template>
          <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
            <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
            <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
          </span>
        </a-form>
      </div>
    </div>
    <!-- table区域-begin -->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <xhdjUserPreferentialCertificate-modal ref="modalForm" @ok="modalFormOk"></xhdjUserPreferentialCertificate-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import XhdjUserPreferentialCertificateModal from './modules/XhdjUserPreferentialCertificateModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'XhdjUserPreferentialCertificateList',
  mixins: [JeecgListMixin],
  components: {
    XhdjUserPreferentialCertificateModal,
  },
  data() {
    return {
      description: '用户卡券表管理页面',
      preferential: {
        1: '不限日期',
        2: '指定到期时间',
        3: '领取后计算到期时间',
      },
      statustype: {
        0: '未领取',
        1: '已领取',
        2: '已到期',
        3: '已使用',
      },
      // 表头
      columns: [
        {
          title: '用户编号',
          align: 'center',
          dataIndex: 'userId',
        },
        {
          title: '用户昵称',
          align: 'center',
          dataIndex: 'nickName',
        },
        {
          title: '用户手机号',
          align: 'center',
          dataIndex: 'phone',
        },
        {
          title: '优惠券模板编号',
          align: 'center',
          dataIndex: 'preferentialCertificateId',
        },
        {
          title: '标题',
          align: 'center',
          dataIndex: 'title',
        },
        {
          title: '使用最小金额',
          align: 'center',
          dataIndex: 'minimumAmount',
          customRender: (text, record) => {
            return parseFloat(record.minimumAmount || 0).toFixed(2) + '元'
          },
        },
        {
          title: '优惠金额',
          align: 'center',
          dataIndex: 'preferentialAmount',
          customRender: (text, record) => {
            return parseFloat(record.preferentialAmount || 0).toFixed(2) + '元'
          },
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status',
          customRender: (text, record) => {
            return this.statustype[record.status]
          },
        },
        {
          // 1-不限日期  2-指定到期时间 3-领取后计算到期时间
          title: '优惠券类型 ',
          align: 'center',
          dataIndex: 'preferentialType',
          customRender: (text, record) => {
            return this.preferential[record.preferentialType]
          },
        },
        {
          title: '开始时间',
          align: 'center',
          dataIndex: 'startTime',
        },
        {
          title: '到期时间',
          align: 'center',
          dataIndex: 'endTime',
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '更新日期',
          align: 'center',
          dataIndex: 'updateTime',
        },
      ],
      url: {
        list: '/user/xhdjUserPreferentialCertificate/backList',
        delete: '/xhdjUserPreferentialCertificate/delete',
        deleteBatch: '/xhdjUserPreferentialCertificate/deleteBatch',
        exportXlsUrl: 'xhdjUserPreferentialCertificate/exportXls',
        importExcelUrl: 'xhdjUserPreferentialCertificate/importExcel',
      },
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {},
}
</script>
<style scoped>
@import '~@assets/less/common.less';
.ant-row {
  display: flex;
  justify-content: flex-end;
}
.ant-col {
  display: flex;
  justify-content: flex-end;
}
.ant-form {
  display: flex;
}
</style>
